package com.tc.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * <p>
 * 通用分页结果对象
 * </p>
 *
 * @author jcd
 * @since 2025-07-09
 */
@Data
@ApiModel(value = "PageResultVO对象", description = "通用分页结果")
public class PageResultVO<T> {

    @ApiModelProperty(value = "总记录数")
    private Long total;

    @ApiModelProperty(value = "当前页码")
    private Long current;

    @ApiModelProperty(value = "每页显示条数")
    private Long size;

    @ApiModelProperty(value = "总页数")
    private Long pages;

    @ApiModelProperty(value = "数据列表")
    private List<T> records;

    /**
     * 将MyBatis-Plus的IPage对象转换为PageResultVO
     *
     * @param page MyBatis-Plus的IPage对象
     * @param records 转换后的记录列表
     * @param <T> 记录类型
     * @return PageResultVO对象
     */
    public static <T> PageResultVO<T> convert(com.baomidou.mybatisplus.core.metadata.IPage<?> page, List<T> records) {
        PageResultVO<T> pageResultVO = new PageResultVO<>();
        pageResultVO.setTotal(page.getTotal());
        pageResultVO.setCurrent(page.getCurrent());
        pageResultVO.setSize(page.getSize());
        pageResultVO.setPages(page.getPages());
        pageResultVO.setRecords(records);
        return pageResultVO;
    }
}